Skip to content

fix(server): reject requests before initialization#2122

Open
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/reject-preinit-requests
Open

fix(server): reject requests before initialization#2122
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/reject-preinit-requests

Conversation

@he-yufeng
Copy link
Copy Markdown

Summary

  • reject non-HTTP server requests before the MCP initialize -> initialized lifecycle completes
  • keep initialize and ping available before initialization
  • leave Streamable HTTP behavior unchanged because that transport already gates initialization itself

Refs modelcontextprotocol/servers#4195.

Validation

  • pnpm --filter @modelcontextprotocol/server exec vitest run test/server/server.test.ts -t "rejects requests before the initialized notification"
  • pnpm --filter @modelcontextprotocol/server test
  • pnpm --filter @modelcontextprotocol/server typecheck
  • pnpm --filter @modelcontextprotocol/server lint
  • git diff --check
  • pre-push hook: workspace typecheck, build, lint

@he-yufeng he-yufeng requested a review from a team as a code owner May 19, 2026 03:21
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 19, 2026

🦋 Changeset detected

Latest commit: 9f795ad

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@modelcontextprotocol/server Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 19, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@2122

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/codemod@2122

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@2122

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@2122

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/fastify@2122

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@2122

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@2122

commit: 9f795ad

@he-yufeng he-yufeng force-pushed the fix/reject-preinit-requests branch from 3668618 to 554a24b Compare May 19, 2026 03:41
@he-yufeng he-yufeng force-pushed the fix/reject-preinit-requests branch from 554a24b to 9f795ad Compare May 27, 2026 10:35
@he-yufeng
Copy link
Copy Markdown
Author

Rebased onto current main, added the server patch changeset, and force-pushed 9f795ad. Local validation: changeset status shows @modelcontextprotocol/server patch; server server.test.ts passed with 2 tests; server typecheck and lint passed; git diff --check passed. Pre-push typecheck, build, and lint also passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant